<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('热采集数据列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 住户资料
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="locationId" name="locationId" th:value="${location.locationId}">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>地址：</label>
                                    <input type="text" id="locationName" name="locationName" th:value="${location.locationName}"/>
                                </li>
                                <li>
                                    <label>热表ID：</label>
                                    <input type="text" id="meterId" name="meterId" th:value="${meterId}"/>
                                </li>
                                <!--<li class="select-time">
                                    <label>采集时间：</label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                                </li>-->
                                <li class="select-time">
                                    <label>查询时间： </label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]" th:value="${beginTime}"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]" th:value="${endTime}"/>
                                </li>
                                <li>
                                    <label>缴费状态：</label>
                                    <select id="status" name="status">
                                        <option value="">所有</option>
                                        <option value="1">缴费</option>
                                        <option value="0">未缴费</option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>


                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: bootstrap-table-export-js" />
    <th:block th:include="include :: bootstrap-table-auto-refresh-js" />
    <th:block th:include="include :: bootstrap-table-print-js" />
    <script th:inline="javascript">
        var prefix = ctx + "data/meter/heatread";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryInfoList();
            queryLocationTree();
        });

        function queryInfoList() {
            var options = {
                url: prefix + "/list",

                modalName: "热表采集数据",
                showExport: true,
                columns: [

                {
                    field: 'location.locationName',
                    title: '地址全称',
                    sortable: true
                },
                {
                    field: 'meterId',
                    title: '热表ID',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.meterId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'heata',
                    title: '本期累计热量',
                    sortable: true
                },
                {
                    field: 'flowa',
                    title: '本期累计流量',
                    sortable: true
                },
                {
                    field: 'heatb',
                    title: '上期累计热量',
                    sortable: true
                },
                {
                    field: 'flowb',
                    title: '上期累计流量',
                    sortable: true
                },
                {
                    field: 'heatc',
                    title: '累计热量差额',
                    sortable: true
                },
                {
                    field: 'flowc',
                    title: '累计流量差额',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '采集时间'
                } ,
                {
                    field: 'status',
                    title: '缴费状态',
                    sortable: true,
                    formatter: function(value, item, index) {
                        if (item.status == '1') {
                            return '<span class="label label-success">缴费</span>';
                        }
                        else {
                            return '<span class="label label-danger">未缴</span>';
                        }
                    }
                }]
            };
            $.table.init(options);
        }

        function queryLocationTree()
        {
            var url = ctx + "base/location/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#locationId").val(treeNode.id);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryLocationTree();
        });
        /* 数据展示 */
        function detail(meterId) {
           // var meterId = $("#meterId").val();
            var url = ctx + 'report/meter/' + meterId;
            $.modal.openTab("热表数据展示", url);
        }
        /**
         * 热表数据采集
         */
        function check(){
            var locationId = $("#locationId").val();
            if(locationId==''){
                $.modal.alertWarning("请先选择采集地址");
                return;
            }
            $.operate.post(prefix + "/check", { "locationId": locationId });
        }

    </script>
</body>
</html>